//
//  Person.m
//  OC02_实例变量可见度_方法
//
//  Created by dllo on 16/2/25.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "Person.h"

@implementation Person

#pragma mark - 自定义初始化方法

- (instancetype)initWithName:(NSString *)name{
    
    self = [super init];
    
    if (self) {
        
        // 实例变量赋值.
        _name = name;
        
    }
    return self;
}


- (instancetype)initWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age{
    
    self = [super init];
    if (self) {
        
        _name = name;
        _sex = sex;
        _age = age;
        
    }
    return self;
}

#pragma mark - 重写init
- (instancetype)init{
    
    // 1. 调用父类的init方法. self 指对象本身.
    self = [super init];
    
    // 加一个判断条件, 当self指针不为空时, 再进行赋值.
    if (self) {
        
        // 2. 给某些实例变量赋值.
        _age = 20;
    }
    
    return self;
}
#pragma mark - 构造器
+ (instancetype)person{
    
    // 1. alloc
    Person *per = [[Person alloc] init];
    
    // 2. 返回对象
    return per;
    
}

+ (instancetype)personWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age{
    
    Person *per = [[Person alloc] initWithName:name sex:sex age:age];
    return per;
    
}



#pragma mark - other
- (void)sayHi{
    NSLog(@"name:%@, sex:%@, age:%ld", _name, _sex, _age);
}

/** 需求: 通过一个方法, 把三个实例变量赋值*/
- (void)name:(NSString *)name sex:(NSString *)sex age:(NSInteger)age{
    
    _name = name;
    _sex = sex;
    _age = age;
    
}
#pragma mark - setter, getter
/** 需求: 通过一个方法, 对_name实例变量赋值 */
- (void)setName:(NSString *)name{
    
    _name = name;
}

/** 需求: 通过一个方法, 取出_name实例变量值. */
- (NSString *)name{
    
    return _name;
}







@end
